updating oE c_func

c_func

<built-in> function c_func(integer rid, sequence args={}) 

calls a C function, machine code function, translated Euphoria function, or compiled Euphoria function by routine id.

Parameters:
  1. rid : an integer, the routine_id of the external function being called.
  2. args : a sequence, the list of parameters to pass to the function
Returns:

An object, whose type and meaning was defined on calling define_c_func.

Errors:

If rid is not a valid routine id, or the arguments do not match the prototype of the routine being called, an error occurs.

Comments:

rid must have been returned by define_c_func, not by routine_id. The type checks are different, and you would get a machine level exception in the best case.

If the function does not take any arguments then args should be {}.

If you pass an argument value which contains a fractional part, where the C function expects a C integer type, the argument will be rounded towards zero. For example: 5.9 will be passed as 5 and -5.9 will be passed as -5.

The function could be part of a .dll or .so created by the Euphoria To C Translator. In this case, a Euphoria atom or sequence could be returned. C and machine code functions can only return integers, or more generally, atoms (IEEE floating-point numbers).

Example 1:
 atom user32, hwnd, ps, hdc 
integer BeginPaint 
 
-- open user32.dll - it contains the BeginPaint C function 
user32 = open_dll("user32.dll") 
 
-- the C function BeginPaint takes a C int argument and 
-- a C pointer, and returns a C int as a result: 
BeginPaint = define_c_func(user32, "BeginPaint", 
                           {C_INT, C_POINTER}, C_INT) 
 
-- call BeginPaint, passing hwnd and ps as the arguments, 
-- hdc is assigned the result: 
hdc = c_func(BeginPaint, {hwnd, ps}) 
See Also:

c_proc, define_c_proc, open_dll, Platform-Specific Issues

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu